import Dialog from '@vant/weapp/dialog/dialog';
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    mainColor: app.globalData.mainColor,
    baseImgUrl: app.globalData.baseImgUrl,
    dataList: [],
    current: 1,
    size: 10,
    stop: false,
    tempData: {},
    showShare: false,
    options: [{
      name: '删除',
      icon: '/images/mine/trash-o.png'
    }, ],
  },

  //数据列表
  getDataList() {
    const that = this;
    if (that.data.stop) {
      return;
    }
    let params = {
      "current": this.data.current,
      "size": this.data.size
    };
    // app.http.post('/gd-fishing/user/collect/list', params).then((res) => {
    //   // console.log('http-res:', JSON.stringify(res));
    //   if (app.errorAlert(res)) {
    //     return;
    //   }
    //   let records = res.data.records;
    //   if (records.length == 0) {
    //     that.setData({
    //       stop: true
    //     });
    //     return;
    //   }
    //   let list = that.data.dataList;
    //   for (let i = 0; i < records.length; i++) {
    //     list.push(records[i]);
    //   }
    //   that.setData({
    //     dataList: list
    //   });
    //   // console.log("dataList:", that.data.dataList);
    // })

    let res = {
      "code": 1,
      "msg": "成功",
      "data": {
        "records": [{
          "infoId": "1854757326750466050",
          "userId": 8,
          "nickName": "月下蓑衣客",
          "headImg": "/20241115/1731634694721.jpeg",
          "infoContent": "滴水湖又名芦潮湖，位于浦东新区南汇新城镇，距离上海市中心约76公里，是南汇新城的中心湖泊。滴水湖呈正圆形，直径约2.6公里，总面积约5.56平方公里，蓄水量约1620万立方米，最深约6.2米，湖面平如镜，岸边花草香，景色影相连，人在岸边游。类似太湖之景致，加上兔耳岭的高山草甸之美，如同远离城市之喧嚣。湖中还有三个总面积为0.48平方公里的小岛，湖水源自大治河，水质为五类地表水。",
          "localName": "环湖西一路儿童乐园",
          "localAddress": "上海市浦东新区南汇新城镇环湖东一路辅路与环湖南一路辅路交叉口西南方向320米左右",
          "lng": "121.949169",
          "lat": "30.887955",
          "createTime": "2024-11-08 13:26",
          "imgList": ["/20241108/1731043557485.jpg", "/20241108/1731043565616.jpg"],
          "concern": true,
          "collect": true,
          "praise": true
        }],
        "total": 1,
        "size": 10,
        "current": 1,
        "pages": 1
      },
      "remarks": null
    };
    let records = res.data.records;
    if (records.length == 0) {
      that.setData({
        stop: true
      });
      return;
    }
    let list = that.data.dataList;
    for (let i = 0; i < records.length; i++) {
      list.push(records[i]);
    }
    that.setData({
      dataList: list
    });
    // console.log("dataList:", that.data.dataList);
  },

  //跳转详情
  toDetail(e) {
    // console.log("------>val:", e.currentTarget.dataset.val);
    if (app.loginAlert()) {
      return;
    }
    wx.navigateTo({
      url: '/pages/info/index?id=' + e.currentTarget.dataset.val.infoId
    })
  },

  //打开编辑
  openEdit(e) {
    // console.log("openEdit:", e.currentTarget.dataset.val);
    this.setData({
      showShare: true,
      tempData: e.currentTarget.dataset.val
    });
  },
  //关闭编辑
  closeEdit() {
    this.setData({
      showShare: false,
      tempData: {}
    });
  },
  //选中编辑
  selectEdit(event) {
    // console.log("selectEdit:", event.detail.name);
    if (event.detail.name == '删除') {
      this.del();
    }
    this.closeEdit();
  },
  //删除
  del() {
    let that = this;
    // console.log("tempData:", this.data.tempData);
    app.http.delete('/gd-fishing/info/del/' + that.data.tempData.infoId).then((res) => {
      // console.log('http-res:', JSON.stringify(res));
      if (app.errorAlert(res)) {
        return;
      }
      that.setData({
        dataList: [],
        current: 1,
        stop: false
      });
      that.getDataList();
      // console.log("dataList:", that.data.dataList);
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getDataList();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    this.setData({
      current: this.data.current + 1
    });
    this.getDataList();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})